package com.ying.myrabbitmq.controller;
import com.ying.myrabbitmq.user.OrderEntity;
import com.ying.myrabbitmq.user.Student;
import com.ying.myrabbitmq.user.User;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RabbitMqController {

    @Autowired
    RabbitTemplate rabbitTemplate;


    @GetMapping("/send")
    public String sendmq() {

        User user = new User().setId(1L).setUsername("我的账号").setPassword("我的密码");
        rabbitTemplate.convertAndSend("ying.exchange", "test", user);

        Student 剑豪 = new Student().setId(1L).setAge(22L).setName("剑豪");
        rabbitTemplate.convertAndSend("ying.exchange", "test", 剑豪);
        return "OK";
    }

    @GetMapping("/send/order")
    public String sendmqorder() {
        OrderEntity orderEntity =new OrderEntity().setId(1L).setOrdernumber("88888888888");
        rabbitTemplate.convertAndSend("order-event-exchange","order.create.order",orderEntity);
        return "OK";
    }

}
